from appium import webdriver
from appium.webdriver.common.mobileby import MobileBy
from appium.webdriver.common.touch_action import TouchAction
import time
import pytest
import allure
@allure.feature("医生APP")
class TestDoctor:
  @pytest.fixture(scope='function',autouse=True)
  def setup(self):
    cap = {
      "platformVersion": "7.1.2",
      "platformName": "Android",
      "deviceName": "d2q",
      "appPackage": "com.threegene.doctor",
      "appActivity": ".module.splash.SplashActivity"
    }
    self.driver = webdriver.Remote("http://localhost:4723/wd/hub", cap)
    self.driver.implicitly_wait(15)
    yield
    self.driver.quit()

  @allure.story("测试登录页面")
  def test_login(self):
    # 通过id方式点击同意
    # self.driver.find_element(MobileBy.ID, "com.threegene.doctor:id/agree_user_agreement_btn").click()
    # 通过class name 一组的方式定位
    self.driver.find_elements(MobileBy.CLASS_NAME,"android.widget.TextView")[2].click()


    # 滑动第一次
    time.sleep(3)
    TouchAction(self.driver).press(x=693, y=1022).move_to(x=43, y=977).release().perform()
    # driver.swipe(start_x=659,start_y=506,end_x=56,end_y=567)
    time.sleep(3)
    # 滑动第二次
    TouchAction(self.driver).press(x=693, y=1022).move_to(x=43, y=977).release().perform()
    # driver.swipe(start_x=693,start_y=1022,end_x=43,end_y=977)
    time.sleep(2)
    # 通过x和y坐标点击
    TouchAction(self.driver).tap(x=350, y=1113).perform()
    # 获取登录文本信息
    text = self.driver.find_element(MobileBy.XPATH, "//*[@text='登录']").text
    assert text == "登录"








